<script setup lang="ts">
//引入图标组件
//深度选择器--- /deep/::v-deep 因为style 这里的scoped时局部样式
import { Search } from "@element-plus/icons-vue";
//收集搜索的关键字
import { ref } from "vue";
import { reqHospitalInfo } from "@/api/home";
import { useRouter } from "vue-router";
import { patch } from "node_modules/axios/index.d.cts";
//创建路由器对象
let $router=useRouter();
let hosname = ref<string>("");

//顶部组件的回调
const fetchData = async (keyword: string, cb: any) => {
  //当用户输入完关键字此函数会执行一次，放请求获取需要展示的数据
  let result: any = await reqHospitalInfo(keyword);
  //给组件提供需要展示的数据
  let showData = result.data.data.map((item:any) => {
    return {
      value: item.hosname,
      hoscode:item.hoscode
    };
  });
  cb(showData);
};
//点击某一个选中项
const goDetail=(item:any)=>
{
  //点击推荐 项目进入医院详情页，将来需要携带query参数(医院的编码)
$router.push({path:'/hospital'})

}
</script>
<script lang="ts">
export default {
  name: "Search",
};
</script>
<template>
  <div class="search">
    <el-autocomplete
      clearable
      placeholder="请输入医院名称"
      :trigger-on-focus="false"
      @select="goDetail"
      v-model="hosname"
      :fetch-suggestions="fetchData"
    />
    <el-button type="primary" size="default" :icon="Search" @click=""
      >搜索</el-button
    >
  </div>
</template>

<style scoped lang="scss">
.search {
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 10px 0;
  ::v-deep(.el-input__wrapper) {
    width: 600px;
    margin-right: 10px;
  }
}
</style>
